/*
 * (C) Copyright 2006-2010 Nuxeo SAS (http://nuxeo.com/) and contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Contributors:
 *     bstefanescu
 */
package org.nuxeo.gwt.habyt.invocation.client;

import java.io.Serializable;

/**
 * TODO: need a field to denote the source client.
 * 
 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
 * 
 */
@SuppressWarnings("serial")
public class Invocation extends Notification implements Serializable {

    protected Invocation() {
    }

    public Invocation(Referenceable target, String action) {
        super(target, action, null);
    }

    public Invocation(Referenceable target, String action, Serializable content) {
        super(target, action, content);
    }

    public static Invocation fromString(String expr) {
        int i = expr.indexOf(':');
        if (i < 1) {
            throw new IllegalArgumentException(
                    "Invalid invocation expression: " + expr);
        }
        String action = expr.substring(0, i);
        expr = expr.substring(i + 1);
        ObjectRef target = new ObjectRef(expr);
        return new Invocation(target, action);
    }
}
